#pragma once
#include<iostream>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

namespace my_std
{
	template<class T,class Container=std::vector<T>>
	class priority_queue
	{
	public:
		void AdUpJust( int child)
		{
			int parent = (child - 1) / 2;
			while (child > 0)
			{
				if (_cons[child] > _cons[parent])
					::swap(_cons[child], _cons[parent]);
				child = parent;
				parent = (child - 1) / 2;
			}
		}

		void push(const T&x)
		{
			_cons.push_back(x);
			AdUpJust(_cons.size() - 1);
		}

		void AdDownJust(int parent)
		{
			int child = parent * 2 + 1;
			while (child < _cons.size())
			{
				if (child + 1 < _cons.size() && _cons[child + 1] > _cons[child])
					++child;
				if (_cons[child] > _cons[parent])
					::swap(_cons[child], _cons[parent]);
				parent = child;
				child = child * 2 + 1;
			}
		}
		void pop()
		{
			::swap(_cons[0], _cons[_cons.size() - 1]);
			_cons.pop_back();
			AdDownJust(0);
		}

		const T&top()const
		{
			return _cons[0];
		}
		bool empty()const 
		{
			return _cons.empty();
		}

		const size_t& size()const
		{
			return _cons.size();
		}
	private:
		Container _cons;
	};
}

namespace my_std1
{
	template<class T>
	struct less
	{
		bool operator()(const T& X1, const T& X2)
		{
			return X1 < X2;
		}
	};
	template<class T>
	struct greater
	{
		bool operator()(const T& X1, const T& X2)
		{
			return X1 > X2;
		}
	};

	template<class T, class Container = std::vector<T>,class Compare=less<T>>
	class priority_queue
	{
	public:
		void AdUpJust(int child)
		{
			int parent = (child - 1) / 2;
			while (child > 0)
			{
				if (_com(_cons[parent], _cons[child] ))
					::swap(_cons[child], _cons[parent]);
				child = parent;
				parent = (child - 1) / 2;
			}
		}

		void push(const T&x)
		{
			_cons.push_back(x);
			AdUpJust(_cons.size() - 1);
		}

		void AdDownJust(int parent)
		{
			int child = parent * 2 + 1;
			while (child < _cons.size())
			{
				if (child + 1 < _cons.size() && _com(_cons[child], _cons[child+1]))
					++child;
				if (_com(_cons[parent], _cons[child]))
					::swap(_cons[child], _cons[parent]);
				parent = child;
				child = child * 2 + 1;
			}
		}
		void pop()
		{
			::swap(_cons[0], _cons[_cons.size() - 1]);
			_cons.pop_back();
			AdDownJust(0);
		}

		const T&top()const
		{
			return _cons[0];
		}
		bool empty()const
		{
			return _cons.empty();
		}

		const size_t& size()const
		{
			return _cons.size();
		}
	private:
		Container _cons;
		Compare _com;
	};
}